package com.zhiwang.planet.mvp.p

import com.zhiwang.planet.di.ActivityScope
import com.zhiwang.planet.mvp.v.ApkUpdateView
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.util.androidSchedule
import com.zhiwang.planet.util.responseFunc
import com.uber.autodispose.AutoDispose.autoDisposable
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.zhiwang.planet.mvp.v.ApkUpdateView2
import com.zhiwang.planet.mvvm.model.entity.main.ImportantNotice
import com.zhiwang.planet.mvvm.viewmodel.ShareViewModel
import com.zhiwang.planet.mvvm.viewmodel.main.sharedViewModels
import javax.inject.Inject

@ActivityScope
class CheckUpdatePresenter @Inject constructor(var restApi: RestApi, var scopeProvider: AndroidLifecycleScopeProvider) {

    var apkUpdateView: ApkUpdateView? = null

    var apkUpdateView2: ApkUpdateView2? = null

    //检查更新
    fun checkUpdate() {

        restApi.checkApkUpdate("http://xq.ji7.com/download/app_android_version")
                .androidSchedule()
                .responseFunc()
                .`as`(autoDisposable(scopeProvider))
                .subscribe({
                    apkUpdateView?.onUpdate(it)
                }, {
                    apkUpdateView?.onError(it)
                }, {

                })
    }


    fun checkUpdate2() {
        restApi.checkApkUpdate("http://xq.ji7.com/download/app_android_version")
                .androidSchedule()
                .responseFunc()
                .`as`(autoDisposable(scopeProvider))
                .subscribe({
                    apkUpdateView2?.onUpdate2(it)
                }, {
                    apkUpdateView2?.onError(it)
                }, {

                })
    }

    fun getImportantNotice(onSuccess:(ImportantNotice)->Unit) {
        var disposable = restApi.getImportantNotice("http://xq.ji7.com/xingqiu/xqnotice")
                .androidSchedule()
                .responseFunc()
                .subscribe({
                    onSuccess(it)
                }, {

                }, {

                })
    }
}